package edu.uiowa.cs.coqview;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

import edu.uiowa.cs.coqview.KeyboardMenu.KMKey;


/* this class will be used to test and develop the API
for the KeyboardMenu being developed */
public class KeyboardMenuTester {
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame jfrm = new JFrame();
				jfrm.setTitle("Keyboard Menu Test");
				jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				
				JTextArea textArea = new JTextArea(5,20);
				textArea.setEditable(false);
				JScrollPane scrollPane = new JScrollPane(textArea);
				
				KeyboardMenu kbm = new KeyboardMenu();
				
				Color lightBlue = new Color(120, 120, 255);
				Color lighterBlue = new Color(200, 200, 255);
				Color lightGreen = new Color(120, 255, 120);
				Color lighterGreen = new Color(200, 255, 200);
				Color lightRed = new Color(255, 120, 120);
				Color lighterRed = new Color(255, 200, 200);
				
				//base card
				KeyboardMenu.KMCard temp1 = kbm.new KMCard(10, 10);
				temp1.setBackPaint(lightBlue);
				temp1.setKeyPaint(lighterBlue);
				temp1.addKey(KMKey.F, "the f key\n==>");
				
				kbm.addKMCard("base", temp1);
				kbm.pushKMCard(kbm.getKMCard("base"));
				
				//base_f card
				KeyboardMenu.KMCard temp2 = kbm.new KMCard(20, 20);
				temp2.setBackPaint(lightGreen);
				temp2.setKeyPaint(lighterGreen);
				temp2.cutHole(KMKey.F);
				temp2.addKey(KMKey.D, "the d key\n==>");
				
				kbm.addKMCard("base_f", temp2);
				temp1.setSubCard(KMKey.F, temp2);
				//kbm.pushKMCard(kbm.getKMCard("base_f"));
				
				//base_fd card
				temp1 = kbm.new KMCard(30, 30);
				temp1.setBackPaint(lightRed);
				temp1.setKeyPaint(lighterRed);
				temp1.cutHole(KMKey.F);
				temp1.cutHole(KMKey.D);
				temp1.addKey(KMKey.J, "the j key");
				
				class JKeyTextAreaAction extends AbstractAction {
					JTextArea textArea;
					JKeyTextAreaAction(JTextArea textArea) {
						this.textArea = textArea;
					}
					public void actionPerformed(ActionEvent e) {
						textArea.append("J was pressed . . .\n");
					}
				}
				temp1.setKeyAction(KMKey.J, new JKeyTextAreaAction(textArea));
				
//				temp1.setKeyAction(KMKey.J, new AbstractAction() {
//					public void actionPerformed(ActionEvent e) {
//						System.out.println("THE J ACTION OF BASE_FD WAS PERFORMED");
//					}
//				});
				
				kbm.addKMCard("base_fd", temp1);
				temp2.setSubCard(KMKey.D, temp1);
				//kbm.pushKMCard(kbm.getKMCard("base_fd"));
				
				JPanel jpnl = new JPanel();
				jpnl.setLayout(new BorderLayout());
				jpnl.add(kbm, BorderLayout.SOUTH);
				
				jpnl.add(scrollPane,BorderLayout.NORTH);
				
				kbm.setKeyBindings(jpnl);
				
				jfrm.add(jpnl);
				
				jpnl.requestFocusInWindow();
				jfrm.pack();
				jfrm.setVisible(true);
			}
		});
	}
}
